function Generic_Number_Image (
   N : Number_Type; 
   Base : Number_Type := 10; 
   Width : Natural := 0; 
   Pad_Char : Character := '0'
   ) return String 
is
   function Get_Auto_Width return Natural 
   is
      w : Natural := 0;
      x : Number_Type := N;
   begin
      loop
         w := w + 1;
         x := x / Base;
         exit when x = 0;
      end loop;
      return w;
   end Get_Auto_Width;

   result : String(1 .. Natural'Max(Get_Auto_Width, Width));

   procedure Build_Result 
   is
      x : Number_Type := N;
      pos : Natural := result'Last;
      tokens : constant array(0 .. 15) of Character := "0123456789ABCDEF";
   begin
      while x /= 0 loop
         declare
            r : Number_Type := X mod base;
         begin
            result(pos) := tokens(Natural(r));
            pos := pos - 1;
            x := x / base;
         end;
      end loop;
   end Build_Result;
begin
   result := (others => Pad_Char);
   Build_Result;
   return result;
end Generic_Number_Image;
